package com.julis.activity.record;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.Constant;
import com.julis.R;
import com.julis.adapter.DOWN2_Adapter;
import com.julis.adapter.DOWN_Adapter;
import com.julis.bean.Obu_Info;
import com.julis.db.Z_ObuInfoDao;
import com.julis.ui.ListViewForScrollView;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 检测记录详情
 */
public class Record_Details_Activity extends AppCompatActivity {


    Z_ObuInfoDao z_obuInfoDao;
    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.vin_code)
    TextView vinCode;
    @BindView(R.id.obu_code)
    TextView obuCode;
    @BindView(R.id.tv_lrvin)
    TextView tvLrvin;
    @BindView(R.id.tv_lrvin_value)
    TextView tvLrvinValue;
    @BindView(R.id.tv_lrvintime)
    TextView tvLrvintime;
    @BindView(R.id.tv_lrvintime_value)
    TextView tvLrvintimeValue;
    @BindView(R.id.tv_lrobu)
    TextView tvLrobu;
    @BindView(R.id.tv_lrobu_value)
    TextView tvLrobuValue;
    @BindView(R.id.tv_lrobutime)
    TextView tvLrobutime;
    @BindView(R.id.tv_lrobutime_value)
    TextView tvLrobutimeValue;
    @BindView(R.id.textView16)
    TextView textView16;

    @BindView(R.id.lanya)
    TextView lanya;
    @BindView(R.id.blecheckvalue)
    TextView blecheckvalue;
    @BindView(R.id.textView14)
    TextView textView14;
    @BindView(R.id.vininputvalue)
    TextView vininputvalue;
    @BindView(R.id.tv_obuchecktime)
    TextView tvObuchecktime;
    @BindView(R.id.obuzijianvalue)
    TextView obuzijianvalue;

    @BindView(R.id.tv_obuchecktime_value)
    TextView tvObuchecktimeValue;
    @BindView(R.id.activity_main)
    LinearLayout activityMain;
    @BindView(R.id.Revin)
    RelativeLayout Revin;
    @BindView(R.id.Revin2)
    RelativeLayout Revin2;
    @BindView(R.id.Revin3)
    RelativeLayout Revin3;
    @BindView(R.id.Revin4)
    RelativeLayout Revin4;
    @BindView(R.id.layout_bluetooth)
    RelativeLayout layout_lanya;
    @BindView(R.id.layout_obuinput1)
    RelativeLayout layout_obuinput1;
    @BindView(R.id.layout_obuinput2)
    RelativeLayout layout_obuinput2;
    @BindView(R.id.layout_zijian)
    RelativeLayout layout_zijian;
    @BindView(R.id.tv_zijian)
    TextView tvZijian;
    @BindView(R.id.lv)
    ListViewForScrollView lv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record_details);
        ButterKnife.bind(this);
        String uuid = getIntent().getStringExtra("uuid");
        z_obuInfoDao = new Z_ObuInfoDao(this);
        Obu_Info obu_infos = z_obuInfoDao.getObu_Info(uuid);
        String ble_check_success = obu_infos.getBle_check_success();
        String Vin_input_success = obu_infos.getVin_input_success();
        String obu_input_success = obu_infos.getObu_input_success();
        String Kl15_success = obu_infos.getKl15_success();
        initadapter();
        if (ble_check_success.equals("")) {
            layout_lanya.setVisibility(View.GONE);
        }
        if (Vin_input_success.equals("")) {
            Revin.setVisibility(View.GONE);
            Revin2.setVisibility(View.GONE);
            Revin3.setVisibility(View.GONE);
            Revin4.setVisibility(View.GONE);
        }
        if (obu_input_success.equals("")) {
            layout_obuinput1.setVisibility(View.GONE);
            layout_obuinput2.setVisibility(View.GONE);
        }
        if (obu_input_success.equals("")) {
            layout_obuinput1.setVisibility(View.GONE);
            layout_obuinput2.setVisibility(View.GONE);
        }
        if (Kl15_success.equals("")) {
            layout_zijian.setVisibility(View.GONE);

        }
        if (Kl15_success.equals("true")) {
            obuzijianvalue.setText("检测成功");
            obuzijianvalue.setTextColor(getResources().getColor(R.color.ym_green));
        } else {
            obuzijianvalue.setText("检测失败");
            obuzijianvalue.setTextColor(getResources().getColor(R.color.red));
        }

        vinCode.setText("VIN码：" + obu_infos.getVincode());
        obuCode.setText("OBU MAC号：" + obu_infos.getObu_code());
        if (obu_infos.getVin_input_success().equals("true")) {
            tvLrvinValue.setText("检测成功");
            tvLrvinValue.setTextColor(getResources().getColor(R.color.ym_green));
        } else {
            tvLrvinValue.setText("检测失败");
            tvLrvinValue.setTextColor(getResources().getColor(R.color.red));
        }
        if (obu_infos.getObu_input_success().equals("true")) {
            tvLrobuValue.setText("检测成功");
            tvLrobuValue.setTextColor(getResources().getColor(R.color.ym_green));
        } else {
            tvLrobuValue.setText("检测失败");
            tvLrobuValue.setTextColor(getResources().getColor(R.color.red));
        }

        if (obu_infos.getBle_check_success().equals("true")) {
            blecheckvalue.setText("检测成功");
            blecheckvalue.setTextColor(getResources().getColor(R.color.ym_green));
        } else {
            blecheckvalue.setText("检测失败");
            blecheckvalue.setTextColor(getResources().getColor(R.color.red));
        }
        if (obu_infos.getVin_write_success().equals("true")) {
            vininputvalue.setText("检测成功");
            vininputvalue.setTextColor(getResources().getColor(R.color.ym_green));
        } else {
            vininputvalue.setText("检测失败");
            vininputvalue.setTextColor(getResources().getColor(R.color.red));
        }
        tvLrvintimeValue.setText(obu_infos.getVin_input_time());
        tvLrobutimeValue.setText(obu_infos.getObu_input_time());
        tvObuchecktimeValue.setText(obu_infos.getDevice_check_device_check_time());

        String obu_check_success = obu_infos.getObu_check_success().substring(1, obu_infos.getObu_check_success().length() - 1);
        String[] arr = obu_check_success.split(","); // 用,分割
        Log.e("zzz", Arrays.toString(arr));
        String data= "OBU"+ Constant.ManufacturerName ;
        textView16.setText(data+arr.length+"次");
        down_adapter.addItem( Arrays.asList(arr));
    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }


    DOWN2_Adapter down_adapter;

    private void initadapter() {
        down_adapter = new DOWN2_Adapter();
        down_adapter.addActivity(this);
        lv.setAdapter(down_adapter);
    }
}
